package com.sun.base;

import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.graphics.Typeface;
import android.os.Bundle;
import android.os.Handler;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.Window;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.sun.bata.LotterData;

public abstract class UserActivity extends Activity
{
	public int test = 2;
	public TextView titleView = null; // title display .if it is null,the
	public boolean noTitle = false;// 是否需要title bar 默认是不需要
	public LinearLayout mainLayout = null;// 主布局
	public LinearLayout contextLayout = null;
	public RelativeLayout titleLayout = null;// title布局
	public LayoutInflater inflater;//
	public int lotterId = LotterData.DOUBLECOLORBALL;
	public Handler handler;
	private boolean landscape = false;

	/***********************************************************
	 * (non-Javadoc)
	 * 
	 * @see android.app.Activity#onCreate(android.os.Bundle)
	 ***********************************************************/
	public void onCreate(Bundle bundle)
	{
		super.onCreate(bundle);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		if (landscape) setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
		else setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
		lotterId = getIntent().getIntExtra("lotterId", LotterData.DOUBLECOLORBALL);
		handler = new Handler();
		contextLayout = new LinearLayout(this);
		contextLayout.setOrientation(LinearLayout.VERTICAL);
		mainLayout = new LinearLayout(this);
		mainLayout.setPadding(12, 12, 12, 12);
		mainLayout.setBackgroundColor(0xff5B5B5B);
		mainLayout.setOrientation(LinearLayout.VERTICAL);
		inflater = LayoutInflater.from(this);	
		initTitle();
		contextLayout.addView(mainLayout, new LinearLayout.LayoutParams(-1, -1));
		init();
		if (noTitle)
		{
			contextLayout.removeView(titleLayout);
			titleLayout = null;
			titleView = null;
		}
		
		this.setContentView(contextLayout);
	}

	private void initTitle()
	{
		RelativeLayout.LayoutParams lParams = new RelativeLayout.LayoutParams(-1, -2);
		lParams.addRule(RelativeLayout.CENTER_IN_PARENT);
		titleView = new TextView(this);
		titleView.setGravity(Gravity.CENTER);
		titleView.setTypeface(Typeface.DEFAULT_BOLD);
		titleView.setTextSize(20);
		titleView.setPadding(0, 3, 0, 3);
		titleLayout = new RelativeLayout(this);
		titleLayout.addView(titleView, lParams);
		contextLayout.addView(titleLayout, new LinearLayout.LayoutParams(-1, -2));
	}

	@Override
	public void setTitle(CharSequence title)
	{
		super.setTitle(title);
		if (titleView != null)
		{
			titleView.setText(title);
		}
	}

	public abstract void init();
}
